package com.framework.bdf4j.tool.gen.service;

import com.framework.bdf4j.tool.gen.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.framework.bdf4j.comm.util.text.Convert;
import com.framework.bdf4j.tool.gen.entity.GenTableColumn;

/**
 * 业务字段 服务层实现
 * 
 */
@Service
public class GenTableColumnServiceImpl extends ServiceImpl<GenTableColumnMapper, GenTableColumn>
    implements IGenTableColumnService {
    @Autowired
    private GenTableColumnMapper genTableColumnMapper;
    @Autowired
    private GenTableColumnOMapper genTableColumnOMapper;
    @Autowired
    private GenTableColumnDMapper genTableColumnDMapper;
    @Autowired
    private GenTableColumnPMapper genTableColumnPMapper;
    @Autowired
    DruidDataSource dataSource;

    private IGenTableColumn getGenTableColumnMapper() {
        String dbtype = dataSource.getDbType();
        if (dbtype.equalsIgnoreCase("oracle")) {
            return genTableColumnOMapper;
        } else if (dbtype.equalsIgnoreCase("db2")) {
            return genTableColumnDMapper;
        } else if (dbtype.equalsIgnoreCase("postgresql")) {
            return genTableColumnPMapper;
        } else {
            return genTableColumnMapper;
        }
    }

    /**
     * 查询业务字段列表
     * 
     * @param genTableColumn
     *            业务字段信息
     * @return 业务字段集合
     */
    @Override
    public IPage selectGenTableColumnListByTableId(Page page, GenTableColumn genTableColumn) {
        return getGenTableColumnMapper().selectGenTableColumnListByTableId(page, genTableColumn);
    }

    /**
     * 新增业务字段
     * 
     * @param genTableColumn
     *            业务字段信息
     * @return 结果
     */
    @Override
    public int insertGenTableColumn(GenTableColumn genTableColumn) {
        return getGenTableColumnMapper().insertGenTableColumn(genTableColumn);
    }

    /**
     * 修改业务字段
     * 
     * @param genTableColumn
     *            业务字段信息
     * @return 结果
     */
    @Override
    public int updateGenTableColumn(GenTableColumn genTableColumn) {
        return getGenTableColumnMapper().updateGenTableColumn(genTableColumn);
    }

    /**
     * 删除业务字段对象
     * 
     * @param ids
     *            需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGenTableColumnByIds(String ids) {
        return getGenTableColumnMapper().deleteGenTableColumnByIds(Convert.toLongArray(ids));
    }
}